﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SmartProduction.Domain.采购委外订单;
using SmartProduction.ErrorCode;
using SmartProduction.Read.API.Application.Commands.DepartCommand;
using SmartProduction.Read.API.Application.Commands.EnterpriseCommand;
using SmartProduction.Read.API.Application.Commands.ProcessRouteCommand;
using SmartProduction.Read.API.Application.Commands.PurchaseCommand;
using SmartProduction.Read.API.Application.Commands.SupplierCommand;
using SmartProduction.Read.API.Dto;

namespace SmartProduction.Read.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class PurchaseReadController : ControllerBase
    {
        private readonly IMediator mediator;

        public PurchaseReadController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 获取部门列表
        /// </summary>
        /// <returns>返回级联列表</returns>
        [HttpGet]
        public async Task<APIResult<List<DepartDto>>> GetDepartments()
        {
            DepartQueryCommand command = new DepartQueryCommand();
            return await mediator.Send(command);
        }
        /// <summary>
        /// 供应商列表显示
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>

        [HttpGet]
        public async Task<APIPaing<List<Supplier>>> SupplierQuery([FromQuery] SupplierQueryCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 工艺路线列表显示
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>

        [HttpGet]
        public async Task<APIPaing<List<ProcessRoute>>> ProcessQuery([FromQuery]ProcessRouteQueryCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 企业显示
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>

        [HttpGet]
        public async Task<APIResult<List<Enterprise>>> EnterpriseQuery([FromQuery]EnterpriseQueryCommand request)
        {
            try
            {
                return await mediator.Send(request);

            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 采购委外显示
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>

        [HttpGet]
        public async Task<APIPaing<List<Purchase>>> PurchaseQuery([FromQuery]PurchaseQueryCommand request)
        {
            try
            {

                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 采购委外详情信息显示
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>

        [HttpGet]
        public async Task<APIPaing<List<PurchasedetailsQueryDto>>> PurchasedetailsQuery([FromQuery]PurchasedetailsQueryCommand request)
        {
            try
            {

                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
